﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ScriptDefineMenu : Editor
{
    static void AddDefine(string symbol)
    {
        string str = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android);
        if (!str.Contains(symbol))
        {
            if (str.EndsWith(";"))
            {
                str += symbol+";";
            }
            else
            {
                str += ";"+ symbol + ";";
            }
            PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, str);
        }
    }
    static void DelDefine(string symbol)
    {
        string str = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android);
        if (str.Contains(symbol+";"))
        {
            str = str.Replace(symbol+";", "");
            PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, str);
        }
        else if (str.Contains(symbol))
        {
            str = str.Replace(symbol, "");
            PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, str);
        }
    }

    [MenuItem("Tools/宏定义/开启log")]
    static void OpenLog()
    {
        AddDefine("OPEN_LOG");
    }

    [MenuItem("Tools/宏定义/关闭log")]
    static void CloseLog()
    {
        DelDefine("OPEN_LOG");
    }

}
